package myky.com.doctorapp.presenter

import io.reactivex.disposables.Disposable
import myky.com.doctorapp.R
import myky.com.doctorapp.base.BasePresenterIm
import myky.com.doctorapp.base.RxSubscribe
import myky.com.doctorapp.contract.RemoteSubmitActivityContract
import myky.com.doctorapp.entity.RecordEntity
import myky.com.doctorapp.entity.RemoteAutoFillEntity
import myky.com.doctorapp.entity.RemoteRepeatEntity
import myky.com.doctorapp.entity.RemoteSubmitEntity
import myky.com.doctorapp.model.RemoteSubmitActivityModel
import myky.com.doctorapp.utils.ToastUtils

/**
 * Description:
 *
 * @author wuyangwuyang
 * Created by 2019/1/11 on 10:27
 */
class RemoteSubmitActivityPresenter :BasePresenterIm<RemoteSubmitActivityContract.View>(), RemoteSubmitActivityContract.Presenter {



    private var remoteSubmitActivityModel:RemoteSubmitActivityModel= RemoteSubmitActivityModel()



    override fun findSubmitData(doctorId:Int) {

        remoteSubmitActivityModel.getAutoFillDate(doctorId).subscribe(object :RxSubscribe<RemoteAutoFillEntity.DataBean>(){
            override fun onSubscribe(d: Disposable) {
                addSubscription(d)
            }

            override fun onSuccess(t: RemoteAutoFillEntity.DataBean?) {
                mView.showDataSuccess(t)
            }

            override fun onFailed(code: Int, msg: String?) {
                mView.showNetErrorView()
            }
        })
    }

    /**
     * 健康档案是否完善
     */
    override fun ishealthperfect() {

        mView.showLoadingView(mContext.resources.getString(R.string.RemoteSubmit_loading))
        remoteSubmitActivityModel.healthperfect().subscribe(object :RxSubscribe<RecordEntity.PayLoadBean>(){

            override fun onSuccess(healthEntity: RecordEntity.PayLoadBean) {
                mView.showResult(healthEntity)
            }

            override fun onFailed(code: Int, msg: String?) {
                mView.hideLoading()
                ToastUtils.show(mContext.resources.getString(R.string.net_exception))
            }

            override fun onSubscribe(d: Disposable) {
                addSubscription(d)
            }


        })
    }

    /**
     * 该医生下是否有远程
     */

    override fun pisRepeat(doctorId: Int) {

        remoteSubmitActivityModel.isRepeat(doctorId).subscribe(object :RxSubscribe<RemoteRepeatEntity.PayLoadBean>(){
            override fun onSuccess(t: RemoteRepeatEntity.PayLoadBean) {
                mView.showContentView()
                mView.hideLoading()
                mView.showRepeat(t)
            }

            override fun onFailed(code: Int, msg: String?) {
                mView.showNetErrorView()
                mView.hideLoading()
            }

            override fun onSubscribe(d: Disposable) {
                addSubscription(d)
                mView.showLoadingView("请稍后")
            }

        })
    }

    /**
     * 创建远程问诊
     */

    override fun pcreateRemote(remoteSubmit: RemoteSubmitEntity) {

        remoteSubmitActivityModel.createRemote(remoteSubmit).subscribe(object :RxSubscribe<RemoteRepeatEntity.PayLoadBean>(){
            override fun onSuccess(t: RemoteRepeatEntity.PayLoadBean) {
                mView.hideLoading()
                mView.showSubmitData(t)
            }

            override fun onFailed(code: Int, msg: String?) {
                mView.hideLoading()
                ToastUtils.show(mContext.resources.getString(R.string.net_exception))
            }

            override fun onSubscribe(d: Disposable) {
                addSubscription(d)
            }

        })
    }
}



